-- copy_attrib
-- created by chendh
-- 天空战附加属性：天空战复制属性
-- ([fire:1,armor:1,speed:1,luck:1]) 复制敌方四维

return {
    -- 空属性
    getEmptyProp = function()
        return {};
    end,

    -- 合并属性
    mergeSkyProp = function(data, addon)
        local result = {};

        if not data then
            result = table.copy(addon);
        else
            result = table.copy(data);

            for style, value in pairs(addon) do
                result[style] = value + (result[style] or 0);
            end
        end

        return result;
    end,

    -- 触发属性
    triggerProp = function(fighter, para)
        local attacker = fighter;
        local defenser = para["target"];
        local args = SkyPropM.getFighterProp(attacker, "copy_attrib");

        -- 免疫能力模拟
        local disableProp = SkyPropM.getFighterProp(defenser, "disable_prop");
        if disableProp["copy_attrib"] and disableProp["copy_attrib"] > 0 then
            return {};
        end

        -- 计算基础属性对换时需要对换的属性路径
        local function changeList(attrib)
            if attrib == "hp" then
                return { "hp" };
            else
                return {
                    attrib,
                    "sky_prop/base_attrib/" .. attrib,
                    "sky_prop/permillage_attrib/" .. attrib,
                    "sky_prop/defenser_attrib/" .. attrib,
                    "sky_prop/defenser_permillage_attrib/" .. attrib,
                };
            end
        end

        -- 因为战斗对象的四维和战斗等属性涉及到固定数值和百分比计算
        -- 因此这里不能直接进行固定值修改
        -- 对换所有需要对换的属性
        for attrib, value in pairs(args) do
            for _, path in ipairs(changeList(attrib)) do
                local temp = defenser.dbase:queryEx(path);

                attacker.dbase:setEx(path, temp);
            end
        end
    end
};